package com.manager.system.controller;

import com.manager.common.annotation.AspectMethodOperation;
import com.manager.common.constant.AspectMethodOperationEnum;
import com.manager.common.vo.PageVO;
import com.manager.common.vo.ResultVO;
import com.manager.model.System_Setting;
import com.manager.system.service.SystemSettingService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/systemSetting")
@SuppressWarnings("all")
public class SystemSettingController {

    @Autowired
    private SystemSettingService systemSettingService;

    @RequestMapping("/getPageMap")
    public PageVO getPageMap(System_Setting model, HttpServletResponse response, HttpServletRequest request) throws Exception{
        PageVO page = systemSettingService.getPageMap(model);
        return page;
    }

    @RequestMapping("/addOrUpdate")
    @AspectMethodOperation(operation = AspectMethodOperationEnum.SAVE)
    public ResultVO addOrUpdate(System_Setting model, HttpServletRequest request, HttpServletResponse response) throws Exception{

        try{
            if(StringUtils.isNotEmpty(model.getId())){
                systemSettingService.updateModel(model);
            }else{
                systemSettingService.addModel(model);
            }
            return ResultVO.success();
        }catch (Exception e){
            return ResultVO.failed(e.getMessage());
        }

    }

    @RequestMapping("/delete")
    @AspectMethodOperation(operation = AspectMethodOperationEnum.DELETE)
    public ResultVO delete(System_Setting model,HttpServletRequest request,HttpServletResponse response) throws Exception{

        try{
           systemSettingService.deleteModel(model);
           return ResultVO.success();
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResultVO.failed();
    }
}
